#include "bios.h"
#include "Tasks.h"
#include "Alarms.h"
#include "Mailboxes.h"

void main(void) 
{
  EnableInterrupts; 
  _DesactivateWatchdog;
  /* OS initialization */
  initOS();
  for(;;) {    
  /* Check if we have a task */  
  if(size)
  {
    taskPrioritize();
    if(fptr->u8contex)
    {
      DisableInterrupts;
      fptr->u8contex=NOCONTEXTED;
      sp=fptr->u16stackPointer;
      aReg=fptr->u8aRegister;
      hReg=fptr->u8hRegister;
      xReg=fptr->u8xRegister;
      ccrReg=fptr->u8ccrRegister;    
      asm
      {
        LDHX goBackSP
        TXS
        LDHX #spAddL
        LDA ,X
        PSHA
        LDHX #spAddH
        LDA ,X
        PSHA
        LDA #0x0
        PSHA
        /* Stablish SR */     
        LDA ccrReg 
        TAP
        /* Stablish A */    
        LDA aReg
        /* Stablish H */      
        LDHX hReg
        /* Stablish X */      
        LDX xReg
        RTC  
      }
    }else{
      if(size)
      {
        EnableInterrupts;
        fptr->funcVoid();      
      }      
    } 
  }  
  EnableInterrupts;
  asm(nop);  
  } 
}

